#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
/**
 * 结构体排序
 * 重载小于号
 * 
 * bool operator< (const Student& t) const
    {
        return score < t.score;
    }
*/
using namespace std;

const int N = 100010;
int n;

struct Student
{
    string name;
    string sno;
    int score;
    bool operator< (const Student& t) const
    {
        return score < t.score;
    }
}q[N];

int main()
{
    cin >> n;
    for(int i = 0; i < n; i ++)
    {
        string name, sno;
        int score;
        cin >> name >> sno >> score;
        q[i] = {name, sno, score};
    }
    sort(q, q + n);
    cout << q[n - 1].name << " " << q[n - 1].sno << endl;
    cout << q[0].name << " " << q[0].sno;
    return 0;
}